//
//  UIBarButtonItem+Extensions.swift
//  传智微博
//
//  Created by apple on 2017/3/20.
//  Copyright © 2017年 CSI. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize，默认 16 号
    ///   - targrt: targrt
    ///   - action: action
    ///   - isBack: 是否是返回按钮，如果是加上尖头
    convenience init(title: String, fontSize: CGFloat = 16, targrt: Any, action: Selector, isBack: Bool = false) {
        
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(targrt, action: action, for: .touchUpInside)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        
        // self.init 实例化 UIBarButtonItem
        self.init(customView: btn)
       
    }
}
